﻿using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using WeatherStationSys.Common;
using WeatherStationSys.Interface;
using WeatherStationSys.Interface.Scheduler;
using WeatherStationSys.UI;

namespace WeatherMonitoringSystem
{
    /// <summary>
    /// 调度器
    /// </summary>
    public class AlarmClock : IClockListener
    {
        private static List<IAlarmListener> _dataContainer;
        private AbstractTemperatureSensor _abstractTemperatureSensor;
        public IAlarmClock AlarmClockImp { get; set; }

        /// <summary>
        /// Ctor
        /// </summary>
        public AlarmClock(StationTookit st)
        {
            _dataContainer = new List<IAlarmListener>();


            AlarmClockImp = st.GetAlarmClock();//创建出具体硬件平台的调度器


            _abstractTemperatureSensor = st.MakeTemperature();//创建出具体硬件平台的温度传感器
            AlarmClockImp.Register(this);

            //观察者
            IObserver tv = new TVMonitoringScreen();
            _abstractTemperatureSensor.AddObserver(tv);
        }

        public void WakeEveryDay(IAlarmListener alarmListener)
        {
            _dataContainer.Add(alarmListener);
        }

        /// <summary>
        /// 抽动
        /// </summary>
        public void Tic()
        {
            _abstractTemperatureSensor.Check();
        }

        /// <summary>
        /// 午夜时分被唤醒
        /// </summary>
        public void Wakeup()
        {
            foreach (var item in _dataContainer)
            {
                //新的1天
                item.Wakeup();
            }
        }
    }
}
